



let resCache = {
    size: 0,
    cache: {},
    addRes(resItem) {
        let key = resItem.getKey();
        if (!this.cache[key]) {
            this.size++;
            this.cache[key] = resItem;
        }
    },

    getRes(key) {
        return this.cache[key];
    },

    load(allloadedcb) {
        let total = this.size;
        let compeleted = 0;
        for (let k in this.cache) {
            this.cache[k].load((ret, key) => {
                if (ret) {
                    compeleted++;
                    if (compeleted >= total) {
                        allloadedcb();
                    }
                } else {
                    console.error(`load key:${key} failed!`);
                }
            });
        }
    }
};

module.exports = resCache;
